//
// Created by lh on 17-9-26.
//

#include <bits/stdc++.h>
using namespace std;
int bookl[64];
int bookr[64];
int num=0;
int result[128];

void dfs(int step,int tar)
{
    int head=0,tail=0;
    if(step>tar)
    {
        for(int pt=head;pt<tail;pt++)
            cout<<result[pt];
        return;
    }
    for(int t=1;t<=num;t++)
    {
        if(!bookl[t]&&!bookr[t])
        {
            int i=step;
            int j=t;
            while(i>=1&&j>=1)
            {
                i--;
                j--;
                if(bookr[i]||bookl[j])
                    goto B;
            }
            i=step;
            j=t;
            while(i<=num&&j<=num)
            {
                i++;
                j++;
                if(bookr[i]||bookl[j])
                    goto B;
            }
            bookl[t]=1;
            bookr[t]=1;
            result[tail++]=t;
            dfs(step+1,tar);
            bookl[t]=0;
            bookr[t]=0;
        }
        B:
        continue;
    }
}
int main()
{
    num=6;
    dfs(1,6);
    return 0;
}
